package com.web.base.core.util;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.blue.jdbc.Page;

import com.web.base.core.message.SequenceRequest;
import com.web.base.core.message.SequenceResponse;
import com.web.base.core.model.Sequence;

/**
 * 序列转换器
 * 
 * @author 代码由 blue-code 框架生成
 * @since 1.0 2018年06月19日
 */
public class SequenceConvertor
{
	private SequenceConvertor()
	{
	}
	
	public static Sequence toSequence(SequenceRequest request)
	{
		if (request == null)
			return null;
		
		Sequence sequence = new Sequence();
		sequence.setId(request.getId());
		sequence.setCode(request.getCode());
		sequence.setName(request.getName());
		sequence.setPrefix(request.getPrefix());
		sequence.setSuffix(request.getSuffix());
		sequence.setVal(request.getVal());
		sequence.setLength(request.getLength());
		sequence.setDate(request.getDate());
		sequence.setDescp(request.getDescp());
		sequence.setType(request.getType());
		sequence.setState(request.getState());
		return sequence;
	}
	
	public static List<Sequence> toSequence(List<SequenceRequest> requestList)
	{
		List<Sequence> list = new ArrayList<>();
		if (requestList == null || requestList.isEmpty())
			return list;
		
		for (SequenceRequest request : requestList)
		{
			list.add(toSequence(request));
		}
		return list;
	}
	
	public static SequenceResponse toResponse(Sequence sequence)
	{
		if (sequence == null)
			return null;
		
		SequenceResponse response = new SequenceResponse();
		response.setId(sequence.getId());
		response.setCode(sequence.getCode());
		response.setName(sequence.getName());
		response.setPrefix(sequence.getPrefix());
		response.setSuffix(sequence.getSuffix());
		response.setVal(sequence.getVal());
		response.setLength(sequence.getLength());
		response.setDate(sequence.getDate());
		response.setDescp(sequence.getDescp());
		response.setType(sequence.getType());
		response.setState(sequence.getState());
		return response;
	}
	
	public static List<SequenceResponse> toResponse(List<Sequence> list)
	{
		List<SequenceResponse> responseList = new ArrayList<>();
		if (list == null || list.isEmpty())
			return responseList;
		
		for (Sequence sequence : list)
		{
			responseList.add(toResponse(sequence));
		}
		return responseList;
	}
	
	public static Map<Integer, SequenceResponse> toResponse(Map<Integer, Sequence> map)
	{
		Map<Integer, SequenceResponse> responseMap = new HashMap<>();
		if (map == null || map.isEmpty())
			return responseMap;
		
		for (Map.Entry<Integer, Sequence> entry : map.entrySet())
		{
			responseMap.put(entry.getKey(), toResponse(entry.getValue()));
		}
		return responseMap;
	}
	
	public static Page<SequenceResponse> toResponse(Page<Sequence> page)
	{
		if (page == null)
			return null;
		
		Page<SequenceResponse> responsePage = new Page<>();
		responsePage.setCurPage(page.getCurPage());
		responsePage.setRows(page.getRows());
		responsePage.setSize(page.getSize());
		responsePage.setStartRowNo(page.getStartRowNo());
		responsePage.setTotalPage(page.getTotalPage());
		responsePage.setObjectList(toResponse(page.getObjectList()));
		return responsePage;
	}
	
}
